export default {
  methods: {
    filterArray(arr) {
      return arr.filter(val => !(!val || val === ''))
    },
    getFullPath(params) {
      return this.getNodeInfo(params)
    },
    renderTreeCheckCallback() {
      this.editPid = this.formPanel.edit.model.funId
    },
    handleNodeAdd(node) {
      if (node && this.formPanel.edit.model.funType === 3) {
        this.$message({
          type: 'error',
          message: '按钮不能创建子节点'
        })
        return
      }
      Object.assign(this.formPanel.add.model, this.initialAddModel)
      if (node) {
        this.currentNode = node
        this.formPanel.add.model[this.pidKey] = node.data[this.nodeIdKey]
        const params = {
          [this.idKey]: node.data[this.nodeIdKey],
          projectId: this.projectId
        }
        this.getNodeInfo(params).then(({
          data
        }) => {
          this.fullPath = data.fullPath ? data.fullPath : '' + data.funName
          this.$set(this.formPanel.add.model, 'fullPath', this.fullPath || '')
        })
      } else {
        this.formPanel.add.model[this.pidKey] = ''
      }
      this.dialogType = this.formPanel.add.type
      this.$nextTick(() => {
        this.$refs.addForm.clearValidate()
        this.labelWidth = "100px"
        const helpUrlFormItem = document.getElementsByClassName('help-url')[0].parentNode.parentNode
        const openNewFormItem = document.getElementsByClassName('open-new')[0].parentNode.parentNode
        helpUrlFormItem.classList.add('menu-item-display-none')
        openNewFormItem.classList.add('menu-item-display-none')
      })
    },
    import: function (data, url = this.importUrl) {
      return this.request({
        url,
        method: 'post',
        headers: {
          'Content-Type': 'multipart/form-data'
        },
        data
      })
    },
  },

}
